package com.pmsystem.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pmsystem.dao.OpinionMapper;
import com.pmsystem.pojo.Administrator;

import com.pmsystem.pojo.Opinion;
import com.pmsystem.util.BeanUtil;

@Service
public class OpinionService {

	
	@Autowired
	private OpinionMapper opinionMapper;
	
	public boolean addOpinion(Opinion opinion) {	
		int flag = opinionMapper.insertSelective(opinion);
		return flag!=0?true:false;
	}

	/**
     * 
     * <p>Title: solveOpinion</p >  
     * <p>Description: 二级管理员处理反馈</p >  
     * @author 泽强
     * @param opinion
     */
	public void solveOpinion(Administrator admin, Opinion opinion) {		
		opinion.setAdminstratorId(admin.getAdminId());
		opinionMapper.solveOpinion(opinion);		
	}
	
	/**
	 * 
	 * <p>Title: findByUserId</p >  
	 * <p>Description: 根据userId查反馈</p >  
	 * @author 泽强
	 * @param userId
	 * @return
	 */
	public List<Opinion> findByUserId(int userId) {
	
		return opinionMapper.findByUserId(userId);
	}

	
	/**
	 * 
	 * <p>Title: findAllOpinion</p >  
	 * <p>Description: 分页查找反馈</p >  
	 * @author 泽强
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public List<Opinion> findAllOpinion(Integer pageNo, Integer pageSize) {
		int start = (pageNo - 1)*pageSize;
		return opinionMapper.findAllOpinion(start,pageSize);
	}

	/**
	 * 
	 * <p>Title: findByAdminId</p >  
	 * <p>Description: 根据adminId查反馈</p >  
	 * @author 泽强
	 * @param adminId
	 * @return
	 */
	public List<Opinion> findByAdminId(Integer adminId) {
		
		return opinionMapper.findByAdminId(adminId);
	}

	/**
	 * 
	 * <p>Title: findOpinion</p >  
	 * <p>Description: 按一定条件查询反馈，注意SQL语句</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	public List<Opinion> findOpinion(Map<String, Object> map) {
		Integer pageNo = (Integer) map.get("pageNo");
		Integer pageSize = (Integer) map.get("pageSize");
		if(pageNo!=null&&pageSize!=null) {
			int start = (pageNo - 1) * pageSize;
			map.put("start", start);
		}	
		return opinionMapper.findOpinion(BeanUtil.mapToMapWithoutNull(map));
	}



}
